package org.linlinjava.litemall.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminShopId;
import org.linlinjava.litemall.admin.service.AdminAccountBookService;
import org.linlinjava.litemall.admin.vo.accountbook.AccountBookImportReqVO;
import org.linlinjava.litemall.admin.vo.accountbook.AccountBookShopListReqVO;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.util.ResponseUtil.ListResponse;
import org.linlinjava.litemall.core.util.ResponseUtil.Response;
import org.linlinjava.litemall.db.domain.LitemallAccountBook;
import org.linlinjava.litemall.db.domain.LitemallAccountBookMonthVo;
import org.linlinjava.litemall.db.dto.LitemallAccountBookFormDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;


@Api(tags = "账本API")
@RestController
@RequestMapping("/admin/account_book")
@RequiredArgsConstructor
@Validated
public class AdminAccountBookController {
	private final AdminAccountBookService litemallAccountBookService;

    @ApiOperation("账本-「列表｜总结」")
    @PostMapping("/shop-list-summary")
    @LogAnno
    public Response shopListSummary(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListSummary(reqVO);
    }

    @ApiOperation("账本-「列表」")
    @PostMapping("/shop-list")
    @LogAnno
    public Response shopList(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopList(reqVO);
    }

    @ApiOperation("账本-「列表｜详情」")
    @PostMapping("/shop-list-details-summary")
    @LogAnno
    public Response shopListDetailsSummary(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListDetailsSummary(reqVO);
    }

    @ApiOperation("账本-「列表｜详情」")
    @PostMapping("/shop-list-details")
    @LogAnno
    public Response shopListDetails(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListDetails(reqVO);
    }

    @ApiOperation("账本-「列表｜账本详情」")
    @PostMapping("/shop-list-book-details")
    @LogAnno
    public Response shopListBookDetails(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListBookDetails(reqVO);
    }


    @ApiOperation("账本-「列表｜账本详情 门店进货订单 概览」")
    @PostMapping("/shop-list-admin-order-summary")
    @LogAnno
    public Response shopListAdminOrderDetailsSummary(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListAdminOrderDetailsSummary(reqVO);
    }

    @ApiOperation("账本-「列表｜账本详情 门店进货订单」")
    @PostMapping("/shop-list-admin-order")
    @LogAnno
    public Response shopListAdminOrderDetails(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListAdminOrderDetails(reqVO);
    }

    @ApiOperation("账本-「列表｜账本详情 订单」")
    @PostMapping("/shop-list-order-details")
    @LogAnno
    public Response shopListOrderDetails(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListOrderDetails(reqVO);
    }

    @ApiOperation("账本-「列表｜详情 额外收入支出 概览」")
    @PostMapping("/shop-list-input-summary")
    @LogAnno
    public Response shopListInputSummary(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListInputSummary(reqVO);
    }


    @ApiOperation("账本-「列表｜详情 额外收入支出」")
    @PostMapping("/shop-list-input")
    @LogAnno
    public Response shopListInput(@RequestBody AccountBookShopListReqVO reqVO) {
        return litemallAccountBookService.shopListInput(reqVO);
    }




    @ApiOperation("账本-「列表｜详情」")
    @GetMapping("/details")
    @LogAnno
    public Response listDetails(@LoginAdminShopId Integer shopId,
                            Integer payType,
                            Integer year,
                            Integer month,
                            @RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer limit) {
        return litemallAccountBookService.listDetails(payType,shopId, year, month, page, limit);
    }

    @ApiOperation("账本-「列表｜月份分组」")
    @GetMapping("/summary")
    @LogAnno
    public Response summary(@LoginAdminShopId Integer shopId,
                          Integer year,
                          Integer month,
                          @RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer limit) {
        return litemallAccountBookService.summary(shopId, year, month, page, limit);
    }

    @ApiOperation("账本-「列表｜月份分组」")
    @GetMapping("/list_month_group")
    @LogAnno
    public Response<ListResponse<LitemallAccountBookMonthVo>> listMounthGroup(@LoginAdminShopId Integer shopId,
    		Integer year,
    		Integer month,
    		@RequestParam(defaultValue = "1") Integer page,
    		@RequestParam(defaultValue = "10") Integer limit) {
        return litemallAccountBookService.listMonthGroup(shopId, year, month, page, limit);
    }

    @ApiOperation("账本-「列表｜门店」")
    @GetMapping("/list")
    @LogAnno
    public Response<ListResponse<LitemallAccountBook>> list(@LoginAdminShopId Integer shopId,
    		@RequestParam Integer year,
    		@RequestParam Integer month,
    		@RequestParam(defaultValue = "1") Integer page,
    		@RequestParam(defaultValue = "10") Integer limit) {
        return litemallAccountBookService.list(shopId, year, month, page, limit);
    }

    @ApiOperation("账本-「进货支出列表｜月份分组」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year",value = "年"),
            @ApiImplicitParam(name = "month",value = "月"),
            @ApiImplicitParam(name = "page",value = "页"),
            @ApiImplicitParam(name = "limit",value = "数")
    })
    @GetMapping("/listMerchandiseByMonth")
    public Response listMerchandise(@ApiIgnore @LoginAdminShopId Integer shopId,
                                    @RequestParam("year") Integer year,
                                    @RequestParam("month") Integer month,
                                    @RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer limit){
        return litemallAccountBookService.listMerchandise(shopId,year,month,page,limit);
    }


    @ApiOperation("账本-「创建账本」")
    @PostMapping("/add")
    @LogAnno
    public Response<Object> create(@LoginAdminShopId Integer shopId, @RequestBody LitemallAccountBookFormDto form) {
        litemallAccountBookService.create(shopId, form);
        return ResponseUtil.ok();
    }

    @ApiOperation("账本-查询导入原料列表")
    @LogAnno
    @GetMapping("/import-shop-merchandise-list-all")
    public ResponseUtil.Response importShopMerchandiseListAll() {
        return litemallAccountBookService.importShopMerchandiseListAll();
    }

    @ApiOperation("账本-「excel导入入库」")
    @PostMapping("/import-shop-merchandise-summary")
    @LogAnno
    public Response importShopMerchandiseSummary( @RequestBody AccountBookImportReqVO reqVO) {
        return litemallAccountBookService.importShopMerchandiseSummary(reqVO);
    }


    @ApiOperation("账本-「excel导入入库」")
    @PostMapping("/import-shop-merchandise")
    @LogAnno
    public Response importShopMerchandise( @RequestBody AccountBookImportReqVO reqVO) {
        return litemallAccountBookService.importShopMerchandise(reqVO);
    }


}
